package com.sixkey.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sixkey.annotation.OperationLog;
import com.sixkey.entity.Reservation;
import com.sixkey.entity.User;
import com.sixkey.entity.vo.ReservationVo;
import com.sixkey.entity.vo.UserVo;
import com.sixkey.response.Response;
import com.sixkey.service.IDepartmentService;
import com.sixkey.service.IReservationService;
import com.sixkey.service.IRoomService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2023-10-05
 */

/**
 * 后台预约会议控制层
 */
@Slf4j
@Validated
@CrossOrigin
@RestController
@RequiredArgsConstructor
@RequestMapping("/reservation")
public class ReservationController {
    private final IReservationService reservationService;

    private final IRoomService roomService;

    private final IDepartmentService departmentService;

    /**
     * 获取预约分页数据
     * @param pageNo
     * @param pageSize
     * @param reservationVo
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
    public Response list(@PathVariable("pageNo") Integer pageNo,
                         @PathVariable("pageSize") Integer pageSize,
                         ReservationVo reservationVo) {
        log.info("获取预约分页数据请求进来");
        Page<Reservation> userPage = reservationService.queryList(pageNo,pageSize,reservationVo);
        return Response.success(userPage );
    }

    /**
     * 新增会议
     * @param reservation
     * @return
     */
    @PostMapping("/save")
    @OperationLog("新增会议")
    public Response save(@RequestBody @Valid Reservation reservation){
        log.info("新增会议请求进来");
        reservationService.saveReservation(reservation);
        return Response.success();
    }

    /**
     * 后台获取部门名称
     * @return
     */
    @GetMapping("/dept")
    public Response list(){
        List<String> list =  departmentService.getDepartmentName();
        return Response.success(list);
    }

    /**
     * 后台获取部门成员
     * @return
     */
    @GetMapping("/deptNumber/{deptName}")
    public Response getDeptNumbers(@PathVariable("deptName") String deptName){
        List<Map<String,Object>> map =  departmentService.getDeptNumbers(deptName);
        return Response.success(map);
    }

    /**
     * 修改会议
     * @param reservation
     * @return
     */
    @PutMapping("/update")
    @OperationLog("修改会议")
    public Response update(@RequestBody @Valid Reservation reservation){
        log.info("修改会议请求进来");
        reservationService.updateReservation(reservation);
        return Response.success();
    }

    /**
     * 会议数据回显
     * @param
     * @return
     */
    @GetMapping("/echo/{id}")
    public Response getReservationInfo(@PathVariable("id") Integer id){
        log.info("会议数据回显请求进来");
        Reservation reservation = reservationService.getReservationById(id);
        return Response.success(reservation);
    }

    /**
     * 删除会议
     * @param
     * @return
     */
    @DeleteMapping("/remove/{id}")
    @OperationLog("删除会议")
    public Response remove(@PathVariable("id") List<Integer> id){
        log.info("删除会议请求进来");
        reservationService.removeBatch(id);
        return Response.success();
    }

    /**
     * 预约管理获取会议室名称数据
     * @return
     */
    @GetMapping("/meetRoomData")
    public Response getMeetRoomData(){
        log.info("获取立即预约会议室名称数据请求进来！");
        List<Map<String,Object>> roomNames = roomService.getMeetRoomNames();
        return Response.success(roomNames);
    }
}
